gdk/win32/gdkprivate-win32.h gdk/win32/gdkglobals-win32.c Add more
authorTor Lillqvist <tml@novell.com>
Tue, 1 Nov 2005 15:29:59 +0000 (15:29 +0000)
committerTor Lillqvist <tml@src.gnome.org>
Tue, 1 Nov 2005 15:29:59 +0000 (15:29 +0000)
2005-11-01  Tor Lillqvist  <tml@novell.com>

* gdk/win32/gdkprivate-win32.h
* gdk/win32/gdkglobals-win32.c
* gdk/win32/gdkmain-win32.c (_gdk_windowing_init): Add more
pre-interned GdkAtoms and pre-registered clipboard formats. Sort
their declarations, definitions and assignments into a more
logical and consistent order.

* gdk/win32/gdkmain-win32.c (_gdk_win32_cf_to_string): Include the
CF_ prefix for the predefined clipboard format names. Put quotes
around registered format names to distinguish them.

* gdk/win32/gdkproperty-win32.c (gdk_property_change): Return
immediately with a warning if the property type is STRING, TEXT,
COMPOUND_TEXT or SAVE_TARGETS, as these are X11-specific that we
should never pretend to handle on Win32. Handle only UTF8_STRING
here, other formats with delayed rendering. Use \uc1 instead of
\uc0 when generating Rich Text Format for easier testability on
XP, where WordPad misinterprets \uc0 encoded characters. Add more
GDK_NOTE debugging output for Clipboard operations.

* gdk/win32/gdkselection-win32.c: Debugging printout improvements.
(gdk_selection_convert): Don't pretent to handle STRING, just
UTF8_STRING. Streamline error handling, don't unnecessarily have a
GError which then isn't used for anything anyway if it gets set.
(gdk_win32_selection_add_targets): Skip also STRING, TEXT,
COMPOUND_TEXT and SAVE_TARGETS in addition to UTF8_STRING.

ChangeLog
ChangeLog.pre-2-10
gdk/win32/gdkglobals-win32.c
gdk/win32/gdkmain-win32.c
gdk/win32/gdkprivate-win32.h
gdk/win32/gdkproperty-win32.c
gdk/win32/gdkselection-win32.c

index cd837c248c443295f7f921c1ee6590a3c48a77bf..89e490c2bbfe763df30b3839188d192551b6fffd 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,32 @@
 2005-11-01  Tor Lillqvist  <tml@novell.com>
 
+       * gdk/win32/gdkprivate-win32.h
+       * gdk/win32/gdkglobals-win32.c
+       * gdk/win32/gdkmain-win32.c (_gdk_windowing_init): Add more
+       pre-interned GdkAtoms and pre-registered clipboard formats. Sort
+       their declarations, definitions and assignments into a more
+       logical and consistent order.
+
+       * gdk/win32/gdkmain-win32.c (_gdk_win32_cf_to_string): Include the
+       CF_ prefix for the predefined clipboard format names. Put quotes
+       around registered format names to distinguish them.
+       
+       * gdk/win32/gdkproperty-win32.c (gdk_property_change): Return
+       immediately with a warning if the property type is STRING, TEXT,
+       COMPOUND_TEXT or SAVE_TARGETS, as these are X11-specific that we
+       should never pretend to handle on Win32. Handle only UTF8_STRING
+       here, other formats with delayed rendering. Use \uc1 instead of
+       \uc0 when generating Rich Text Format for easier testability on
+       XP, where WordPad misinterprets \uc0 encoded characters. Add more
+       GDK_NOTE debugging output for Clipboard operations.
+
+       * gdk/win32/gdkselection-win32.c: Debugging printout improvements.
+       (gdk_selection_convert): Don't pretent to handle STRING, just
+       UTF8_STRING. Streamline error handling, don't unnecessarily have a
+       GError which then isn't used for anything anyway if it gets set.
+       (gdk_win32_selection_add_targets): Skip also STRING, TEXT,
+       COMPOUND_TEXT and SAVE_TARGETS in addition to UTF8_STRING.
+
        * config.h.win32.in: Sync with what configure produces.
 
        * configure.in: Don't look for X_PACKAGES unless building for
index cd837c248c443295f7f921c1ee6590a3c48a77bf..89e490c2bbfe763df30b3839188d192551b6fffd 100644 (file)
@@ -1,5 +1,32 @@
 2005-11-01  Tor Lillqvist  <tml@novell.com>
 
+       * gdk/win32/gdkprivate-win32.h
+       * gdk/win32/gdkglobals-win32.c
+       * gdk/win32/gdkmain-win32.c (_gdk_windowing_init): Add more
+       pre-interned GdkAtoms and pre-registered clipboard formats. Sort
+       their declarations, definitions and assignments into a more
+       logical and consistent order.
+
+       * gdk/win32/gdkmain-win32.c (_gdk_win32_cf_to_string): Include the
+       CF_ prefix for the predefined clipboard format names. Put quotes
+       around registered format names to distinguish them.
+       
+       * gdk/win32/gdkproperty-win32.c (gdk_property_change): Return
+       immediately with a warning if the property type is STRING, TEXT,
+       COMPOUND_TEXT or SAVE_TARGETS, as these are X11-specific that we
+       should never pretend to handle on Win32. Handle only UTF8_STRING
+       here, other formats with delayed rendering. Use \uc1 instead of
+       \uc0 when generating Rich Text Format for easier testability on
+       XP, where WordPad misinterprets \uc0 encoded characters. Add more
+       GDK_NOTE debugging output for Clipboard operations.
+
+       * gdk/win32/gdkselection-win32.c: Debugging printout improvements.
+       (gdk_selection_convert): Don't pretent to handle STRING, just
+       UTF8_STRING. Streamline error handling, don't unnecessarily have a
+       GError which then isn't used for anything anyway if it gets set.
+       (gdk_win32_selection_add_targets): Skip also STRING, TEXT,
+       COMPOUND_TEXT and SAVE_TARGETS in addition to UTF8_STRING.
+
        * config.h.win32.in: Sync with what configure produces.
 
        * configure.in: Don't look for X_PACKAGES unless building for
index a178ccbf25af0eac9f394bcab0515bfb864c8054..dce7cba73f6b0d5ce6094f5fa428e7cb687c3465 100644 (file)
@@ -48,10 +48,15 @@ UINT                  _gdk_input_codepage;
 
 WORD             _cf_rtf;
 WORD             _cf_utf8_string;
+WORD             _cf_image_bmp;
 
-GdkAtom           _utf8_string;
+GdkAtom           _gdk_selection_property;
+GdkAtom                  _wm_transient_for;
 GdkAtom                  _targets;
-
+GdkAtom                  _save_targets;
+GdkAtom           _utf8_string;
+GdkAtom                  _text;
+GdkAtom                  _compound_text;
 GdkAtom                  _text_uri_list;
 GdkAtom                  _image_bmp;
 
@@ -59,10 +64,6 @@ GdkAtom                _local_dnd;
 GdkAtom                  _gdk_win32_dropfiles;
 GdkAtom                  _gdk_ole2_dnd;
 
-GdkAtom           _gdk_selection_property;
-
-GdkAtom                  _wm_transient_for;
-
 gint             _gdk_input_ignore_wintab = FALSE;
 gint             _gdk_max_colors = 0;
 
index 66d24ff559e5634e32989bac9077a352a5440c59..0c4be65f21e9b4f0689200b3ce91e7bbe8290a15 100644 (file)
@@ -110,10 +110,15 @@ _gdk_windowing_init (void)
 
   _cf_rtf = RegisterClipboardFormat ("Rich Text Format");
   _cf_utf8_string = RegisterClipboardFormat ("UTF8_STRING");
+  _cf_image_bmp = RegisterClipboardFormat ("image/bmp");
 
-  _utf8_string = gdk_atom_intern ("UTF8_STRING", FALSE);
+  _gdk_selection_property = gdk_atom_intern ("GDK_SELECTION", FALSE);
+  _wm_transient_for = gdk_atom_intern ("WM_TRANSIENT_FOR", FALSE);
   _targets = gdk_atom_intern ("TARGETS", FALSE);
-
+  _save_targets = gdk_atom_intern ("SAVE_TARGETS", FALSE);
+  _utf8_string = gdk_atom_intern ("UTF8_STRING", FALSE);
+  _text = gdk_atom_intern ("TEXT", FALSE);
+  _compound_text = gdk_atom_intern ("COMPOUND_TEXT", FALSE);
   _text_uri_list = gdk_atom_intern ("text/uri-list", FALSE);
   _image_bmp = gdk_atom_intern ("image/bmp", FALSE);
 
@@ -121,10 +126,6 @@ _gdk_windowing_init (void)
   _gdk_win32_dropfiles = gdk_atom_intern ("DROPFILES_DND", FALSE);
   _gdk_ole2_dnd = gdk_atom_intern ("OLE2_DND", FALSE);
 
-  _gdk_selection_property = gdk_atom_intern ("GDK_SELECTION", FALSE);
-
-  _wm_transient_for = gdk_atom_intern ("WM_TRANSIENT_FOR", FALSE);
-
   _gdk_win32_selection_init ();
 }
 
@@ -932,7 +933,7 @@ _gdk_win32_cf_to_string (UINT format)
 
   switch (format)
     {
-#define CASE(x) case CF_##x: return #x
+#define CASE(x) case CF_##x: return "CF_" #x
       CASE (BITMAP);
       CASE (DIB);
 #ifdef CF_DIBV5
@@ -965,7 +966,7 @@ _gdk_win32_cf_to_string (UINT format)
          format <= CF_PRIVATELAST)
        return static_printf ("CF_PRIVATE%d", format - CF_PRIVATEFIRST);
       if (GetClipboardFormatName (format, buf, sizeof (buf)))
-       return static_printf ("%s", buf);
+       return static_printf ("'%s'", buf);
       else
        return static_printf ("unk-%#lx", format);
     }
index d76c8cb51ec22284524a4942e9bfd2cbdbc4b316..2ec70d49f8695831cd6572c6d1eb446ac2727247 100644 (file)
@@ -472,11 +472,16 @@ extern guint               _scancode_rshift;
 /* Registered clipboard formats */
 extern WORD             _cf_rtf;
 extern WORD             _cf_utf8_string;
+extern WORD             _cf_image_bmp;
 
-/* GdkAtoms: targets */
-extern GdkAtom           _utf8_string;
+/* GdkAtoms: properties, targets and types */
+extern GdkAtom          _gdk_selection_property;
+extern GdkAtom          _wm_transient_for;
 extern GdkAtom          _targets;
-
+extern GdkAtom          _save_targets;
+extern GdkAtom           _utf8_string;
+extern GdkAtom          _text;
+extern GdkAtom          _compound_text;
 extern GdkAtom          _text_uri_list;
 extern GdkAtom          _image_bmp;
 
@@ -485,10 +490,6 @@ extern GdkAtom           _local_dnd;
 extern GdkAtom          _gdk_win32_dropfiles;
 extern GdkAtom          _gdk_ole2_dnd;
 
-extern GdkAtom          _gdk_selection_property;
-
-extern GdkAtom          _wm_transient_for;
-
 /* Options */
 extern gboolean                 _gdk_input_ignore_wintab;
 extern gint             _gdk_max_colors;
index 5eff72add0fce4d233ed42a1e5104661f6dbbfbd..9d7dc12f76384bdc4b64b9fa24c454080ade0420 100644 (file)
@@ -287,12 +287,17 @@ gdk_property_change (GdkWindow    *window,
             g_free (prop_name),
             g_free (type_name)));
 
+  /* We should never come here for these types */
+  g_return_if_fail (type != GDK_TARGET_STRING);
+  g_return_if_fail (type != _text);
+  g_return_if_fail (type != _compound_text);
+  g_return_if_fail (type != _save_targets);
+
   if (property == _gdk_selection_property
       && format == 8
       && mode == GDK_PROP_MODE_REPLACE)
     {
-      if ((type == GDK_TARGET_STRING && GetACP () == 1252) ||
-         type == _utf8_string)
+      if (type == _utf8_string)
        {
          if (!OpenClipboard (GDK_WINDOW_HWND (window)))
            {
@@ -300,29 +305,17 @@ gdk_property_change (GdkWindow    *window,
              return;
            }
 
-         if (type == _utf8_string)
-           {
-             /* Check if only ASCII */
-             for (i = 0; i < nelements; i++)
-               if (data[i] >= 0200)
-                 break;
-           }
-         else /* if (type == GDK_TARGET_STRING) */
-           {
-             /* Check that no 0200..0240 chars present, as they
-              * differ between ISO-8859-1 and CP1252.
-              */
-             for (i = 0; i < nelements; i++)
-               if (data[i] >= 0200 && data[i] < 0240)
-                 break;
-           }
          nchars = g_utf8_strlen (data, nelements);
 
+         /* Check if only ASCII */
+         for (i = 0; i < nelements; i++)
+           if (data[i] >= 0200)
+             break;
+
          if (i == nelements)
            {
-             /* If UTF-8 and only ASCII, or if STRING (ISO-8859-1)
-              * and system codepage is CP1252, use CF_TEXT and the
-              * data as such.
+             /* If UTF-8 and only ASCII, use CF_TEXT and the data as
+              * such.
               */
              method = SYSTEM_CODEPAGE;
              size = nelements;
@@ -360,8 +353,16 @@ gdk_property_change (GdkWindow    *window,
 
              const guchar *p = data;
 
+             /* WordPad on XP, at least, doesn't seem to grok \uc0
+              * -encoded Unicode characters. Oh well, use \uc1 then,
+              * with a question mark as the "ANSI" stand-in for each
+              * non-ASCII Unicode character. (WordPad for XP? This
+              * code path is for Win9x! Yes, but I don't have Win9x,
+              * so I use XP to test, using the G_WIN32_PRETEND_WIN9X
+              * environment variable.)
+              */
              method = RICH_TEXT;
-             rtf = g_string_new ("{\\rtf1\\uc0 ");
+             rtf = g_string_new ("{\\rtf1\\uc1 ");
 
              while (p < data + nelements)
                {
@@ -383,11 +384,11 @@ gdk_property_change (GdkWindow    *window,
                      guchar *q;
                      gint n;
                      
-                     rtf = g_string_append (rtf, "\\uNNNNN ");
-                     rtf->len -= 6; /* five digits and a space */
+                     rtf = g_string_append (rtf, "\\uNNNNN ?");
+                     rtf->len -= 7; /* five digits a space and a question mark */
                      q = rtf->str + rtf->len;
-                     n = g_sprintf (q, "%d ", g_utf8_get_char (p));
-                     g_assert (n <= 6);
+                     n = g_sprintf (q, "%d ?", g_utf8_get_char (p));
+                     g_assert (n <= 7);
                      rtf->len += n;
                      
                      p = g_utf8_next_char (p);
@@ -444,8 +445,10 @@ gdk_property_change (GdkWindow    *window,
                  lcidptr = GlobalLock (hlcid);
                  *lcidptr = lcid;
                  GlobalUnlock (hlcid);
+                 GDK_NOTE (DND, g_print ("... SetClipboardData(CF_LOCALE,%p)\n",
+                                         hlcid));
                  if (!SetClipboardData (CF_LOCALE, hlcid))
-                   WIN32_API_FAILED ("SetClipboardData (CF_LOCALE)"), ok = FALSE;
+                   WIN32_API_FAILED ("SetClipboardData(CF_LOCALE)"), ok = FALSE;
                }
              break;
 
@@ -464,8 +467,10 @@ gdk_property_change (GdkWindow    *window,
                  guchar *utf8ptr = GlobalLock (hutf8);
                  memmove (utf8ptr, data, nelements);
                  GlobalUnlock (hutf8);
+                 GDK_NOTE (DND, g_print ("... SetClipboardData('UTF8_STRING',%p)\n",
+                                         hutf8));
                  if (!SetClipboardData (_cf_utf8_string, hutf8))
-                   WIN32_API_FAILED ("SetClipboardData (UTF8_STRING)");
+                   WIN32_API_FAILED ("SetClipboardData('UTF8_STRING')");
                }
              break;
 
@@ -474,6 +479,8 @@ gdk_property_change (GdkWindow    *window,
            }
 
          GlobalUnlock (hdata);
+         GDK_NOTE (DND, g_print ("... SetClipboardData(%s,%p)\n",
+                                 _gdk_win32_cf_to_string (cf), hdata));
          if (ok && !SetClipboardData (cf, hdata))
            WIN32_API_FAILED ("SetClipboardData"), ok = FALSE;
       
@@ -482,6 +489,7 @@ gdk_property_change (GdkWindow    *window,
        }
       else
         {
+         GDK_NOTE (DND, g_print ("... delayed rendering\n"));
          /* Delayed Rendering. We can't assign hdata to the clipboard
           * here as type may be "image/png", "image/jpg", etc.  In
           * this case there's a further conversion afterwards.
index 82e3699add30bced6ad538f07c09acce41b98a46..ac359b7b112ae8f835f7a7ff92ab81bed31660ae 100644 (file)
@@ -201,17 +201,22 @@ gdk_selection_owner_set_for_display (GdkDisplay *display,
 {
   HWND hwnd;
   GdkEvent tmp_event;
-  gchar *sel_name;
 
   g_return_val_if_fail (display == _gdk_display, FALSE);
   g_return_val_if_fail (selection != GDK_NONE, FALSE);
 
-  GDK_NOTE (DND,
-           (sel_name = gdk_atom_name (selection),
-            g_print ("gdk_selection_owner_set: %p %#x (%s)\n",
-                     (owner ? GDK_WINDOW_HWND (owner) : NULL),
-                     (guint) selection, sel_name),
-            g_free (sel_name)));
+#ifdef G_ENABLE_DEBUG
+  {
+    gchar *sel_name;
+
+    GDK_NOTE (DND,
+             (sel_name = gdk_atom_name (selection),
+              g_print ("gdk_selection_owner_set_for_display: %p %#x (%s)\n",
+                       (owner ? GDK_WINDOW_HWND (owner) : NULL),
+                       (guint) selection, sel_name),
+              g_free (sel_name)));
+  }
+#endif
 
   if (selection != GDK_SELECTION_CLIPBOARD)
     {
@@ -237,6 +242,7 @@ gdk_selection_owner_set_for_display (GdkDisplay *display,
     return FALSE;
 
   _ignore_destroy_clipboard = TRUE;
+  GDK_NOTE (DND, g_print ("... EmptyClipboard()\n"));
   if (!API_CALL (EmptyClipboard, ()))
     {
       _ignore_destroy_clipboard = FALSE;
@@ -275,7 +281,6 @@ gdk_selection_owner_get_for_display (GdkDisplay *display,
                                      GdkAtom     selection)
 {
   GdkWindow *window;
-  gchar *sel_name;
 
   g_return_val_if_fail (display == _gdk_display, NULL);
   g_return_val_if_fail (selection != GDK_NONE, NULL);
@@ -292,12 +297,18 @@ gdk_selection_owner_get_for_display (GdkDisplay *display,
 
   window = gdk_window_lookup ((GdkNativeWindow) g_hash_table_lookup (sel_owner_table, selection));
 
-  GDK_NOTE (DND,
-           (sel_name = gdk_atom_name (selection),
-            g_print ("gdk_selection_owner_get: %#x (%s) = %p\n",
-                     (guint) selection, sel_name,
-                     (window ? GDK_WINDOW_HWND (window) : NULL)),
-            g_free (sel_name)));
+#ifdef G_ENABLE_DEBUG
+  {
+    gchar *sel_name;
+    
+    GDK_NOTE (DND,
+             (sel_name = gdk_atom_name (selection),
+              g_print ("gdk_selection_owner_get: %#x (%s) = %p\n",
+                       (guint) selection, sel_name,
+                       (window ? GDK_WINDOW_HWND (window) : NULL)),
+              g_free (sel_name)));
+  }
+#endif
 
   return window;
 }
@@ -331,8 +342,6 @@ gdk_selection_convert (GdkWindow *requestor,
 {
   HGLOBAL hdata;
   GdkAtom property = _gdk_selection_property;
-  gchar *sel_name, *tgt_name;
-  GError *error = NULL;
 
   g_return_if_fail (selection != GDK_NONE);
   g_return_if_fail (requestor != NULL);
@@ -340,15 +349,21 @@ gdk_selection_convert (GdkWindow *requestor,
   if (GDK_WINDOW_DESTROYED (requestor))
     return;
 
-  GDK_NOTE (DND,
-           (sel_name = gdk_atom_name (selection),
-            tgt_name = gdk_atom_name (target),
-            g_print ("gdk_selection_convert: %p %#x (%s) %#x (%s)\n",
-                     GDK_WINDOW_HWND (requestor),
-                     (guint) selection, sel_name,
-                     (guint) target, tgt_name),
-            g_free (sel_name),
-            g_free (tgt_name)));
+#ifdef G_ENABLE_DEBUG
+  {
+    gchar *sel_name, *tgt_name;
+    
+    GDK_NOTE (DND,
+             (sel_name = gdk_atom_name (selection),
+              tgt_name = gdk_atom_name (target),
+              g_print ("gdk_selection_convert: %p %#x (%s) %#x (%s)\n",
+                       GDK_WINDOW_HWND (requestor),
+                       (guint) selection, sel_name,
+                       (guint) target, tgt_name),
+              g_free (sel_name),
+              g_free (tgt_name)));
+  }
+#endif
 
   if (selection == GDK_SELECTION_CLIPBOARD && target == _targets)
     {
@@ -401,16 +416,14 @@ gdk_selection_convert (GdkWindow *requestor,
        data[i++] = _image_bmp;
 
       if (i > 0)
-         _gdk_selection_property_store (requestor, GDK_SELECTION_TYPE_ATOM,
-                                        32, (guchar *) data, i * sizeof (GdkAtom));
+       _gdk_selection_property_store (requestor, GDK_SELECTION_TYPE_ATOM,
+                                      32, (guchar *) data, i * sizeof (GdkAtom));
       else             
        property = GDK_NONE;
 
       API_CALL (CloseClipboard, ());
     }
-  else if (selection == GDK_SELECTION_CLIPBOARD &&
-          (target == GDK_TARGET_STRING ||
-           target == _utf8_string))
+  else if (selection == GDK_SELECTION_CLIPBOARD && target == _utf8_string)
     {
       /* Converting the CLIPBOARD selection means he wants the
        * contents of the clipboard. Get the clipboard data, and store
@@ -448,14 +461,10 @@ gdk_selection_convert (GdkWindow *requestor,
                  p++;
                }
 
-             data = g_utf16_to_utf8 (wcs, wclen, NULL, NULL, &error);
+             data = g_utf16_to_utf8 (wcs, wclen, NULL, NULL, NULL);
              g_free (wcs);
 
-             if (!data)
-               {
-                 g_error_free (error);
-               }
-             else
+             if (data)
                _gdk_selection_property_store (requestor, target, 8,
                                               data, strlen (data) + 1);
              GlobalUnlock (hdata);
@@ -532,12 +541,10 @@ gdk_selection_convert (GdkWindow *requestor,
                }
              g_free (wcs);
 
-             data = g_utf16_to_utf8 (wcs2, wclen2, NULL, &length, &error);
+             data = g_utf16_to_utf8 (wcs2, wclen2, NULL, &length, NULL);
              g_free (wcs2);
 
-             if (!data)
-               g_error_free (error);
-             else
+             if (data)
                _gdk_selection_property_store (requestor, target, 8,
                                               data, length + 1);
              GlobalUnlock (hdata);
@@ -548,14 +555,13 @@ gdk_selection_convert (GdkWindow *requestor,
 
       API_CALL (CloseClipboard, ());
     }
-  else if (selection == GDK_SELECTION_CLIPBOARD &&
-           target == _image_bmp)
+  else if (selection == GDK_SELECTION_CLIPBOARD && target == _image_bmp)
     {
       guchar *data;
 
       if (!API_CALL (OpenClipboard, (GDK_WINDOW_HWND (requestor))))
        return;
-      if ((hdata = GetClipboardData (RegisterClipboardFormat ("image/bmp"))) != NULL)
+      if ((hdata = GetClipboardData (_cf_image_bmp)) != NULL)
        {
          /* "image/bmp" is the first choice. */
          guchar *ptr;
@@ -751,24 +757,26 @@ gdk_selection_send_notify_for_display (GdkDisplay *display,
                                        GdkAtom     property,
                                        guint32     time)
 {
-#ifdef G_ENABLE_DEBUG
-  gchar *sel_name, *tgt_name, *prop_name;
-#endif
-
   g_return_if_fail (display == _gdk_display);
 
-  GDK_NOTE (DND,
-           (sel_name = gdk_atom_name (selection),
-            tgt_name = gdk_atom_name (target),
-            prop_name = gdk_atom_name (property),
-            g_print ("gdk_selection_send_notify_for_display: %#x %#x (%s) %#x (%s) %#x (%s)\n",
-                     requestor,
-                     (guint) selection, sel_name,
-                     (guint) target, tgt_name,
-                     (guint) property, prop_name),
-            g_free (sel_name),
-            g_free (tgt_name),
-            g_free (prop_name)));
+#ifdef G_ENABLE_DEBUG
+  {
+    gchar *sel_name, *tgt_name, *prop_name;
+
+    GDK_NOTE (DND,
+             (sel_name = gdk_atom_name (selection),
+              tgt_name = gdk_atom_name (target),
+              prop_name = gdk_atom_name (property),
+              g_print ("gdk_selection_send_notify_for_display: %p %#x (%s) %#x (%s) %#x (%s)\n",
+                       (gpointer) requestor,
+                       (guint) selection, sel_name,
+                       (guint) target, tgt_name,
+                       (guint) property, prop_name),
+              g_free (sel_name),
+              g_free (tgt_name),
+              g_free (prop_name)));
+  }
+#endif
 }
 
 /* It's hard to say whether implementing this actually is of any use
@@ -783,18 +791,23 @@ gdk_text_property_to_text_list_for_display (GdkDisplay   *display,
                                            gint          length,
                                            gchar      ***list)
 {
-  gchar *enc_name;
   gchar *result;
   const gchar *charset;
   gchar *source_charset;
 
   g_return_val_if_fail (display == _gdk_display, 0);
 
-  GDK_NOTE (DND, (enc_name = gdk_atom_name (encoding),
-                 g_print ("gdk_text_property_to_text_list_for_display: %s %d %.20s %d\n",
-                          enc_name, format, text, length),
-                 g_free (enc_name)));
-
+#ifdef G_ENABLE_DEBUG
+  {
+    gchar *enc_name;
+
+    GDK_NOTE (DND, (enc_name = gdk_atom_name (encoding),
+                   g_print ("gdk_text_property_to_text_list_for_display: %s %d %.20s %d\n",
+                            enc_name, format, text, length),
+                   g_free (enc_name)));
+  }
+#endif
+    
   if (!list)
     return 0;
 
@@ -1021,6 +1034,27 @@ gdk_win32_selection_add_targets (GdkWindow  *owner,
   GSList *convertable_formats, *format;
   gboolean has_set_dib = FALSE, has_real_dib = FALSE;
 
+#ifdef G_ENABLE_DEBUG
+  if (_gdk_debug_flags & GDK_DEBUG_DND)
+    {
+      gchar *sel_name = gdk_atom_name (selection);
+      
+      g_print ("gdk_win32_selection_add_targets: %p: %s: ",
+              owner ? GDK_WINDOW_HWND (owner) : NULL,
+              sel_name);
+      g_free (sel_name);
+
+      for (i = 0; i < n_targets; i++)
+       {
+         gchar *tgt_name = gdk_atom_name (targets[i]);
+
+         g_print ("%s ", tgt_name);
+         g_free (tgt_name);
+       }
+      g_print ("\n");
+    }
+#endif
+
   if (selection != GDK_SELECTION_CLIPBOARD)
     return;
 
@@ -1039,17 +1073,25 @@ gdk_win32_selection_add_targets (GdkWindow  *owner,
     {
       gchar *target_name;
 
-      if (targets[i] == _utf8_string)
+      if (targets[i] == _utf8_string ||
+         targets[i] == GDK_TARGET_STRING ||
+         targets[i] == _text ||
+         targets[i] == _compound_text ||
+         targets[i] == _save_targets)
        continue;
 
       target_name = gdk_atom_name (targets[i]);
-      if (!(formatid = RegisterClipboardFormat (target_name))) {
-       WIN32_API_FAILED ("RegisterClipboardFormat");
-       API_CALL (CloseClipboard, ());
-       g_free (target_name);
-       return;
-      }
+      if (!(formatid = RegisterClipboardFormat (target_name)))
+       {
+         WIN32_API_FAILED ("RegisterClipboardFormat");
+         API_CALL (CloseClipboard, ());
+         g_free (target_name);
+         return;
+       }
       g_hash_table_replace (_format_atom_table, GINT_TO_POINTER (formatid), targets[i]);
+
+      GDK_NOTE (DND, g_print ("... SetClipboardData(%s,NULL)\n",
+                             _gdk_win32_cf_to_string (formatid)));
       SetClipboardData (formatid, NULL);
 
       /* We should replace the previous image format associated with
@@ -1064,10 +1106,12 @@ gdk_win32_selection_add_targets (GdkWindow  *owner,
          g_hash_table_replace (_format_atom_table,
                                GINT_TO_POINTER (CF_DIB),
                                targets[i]);
-         if (!has_set_dib) {
-           SetClipboardData (CF_DIB, NULL);
-           has_set_dib = TRUE;
-         }
+         if (!has_set_dib)
+           {
+             GDK_NOTE (DND, g_print ("... SetClipboardData(CF_DIB,NULL)\n"));
+             SetClipboardData (CF_DIB, NULL);
+             has_set_dib = TRUE;
+           }
          has_real_dib = TRUE;
          g_free (target_name);
          continue;
@@ -1085,6 +1129,7 @@ gdk_win32_selection_add_targets (GdkWindow  *owner,
                  g_hash_table_replace (_format_atom_table,
                                        GINT_TO_POINTER (CF_DIB),
                                        targets[i]);
+                 GDK_NOTE (DND, g_print ("... SetClipboardData(CF_DIB,NULL)\n"));
                  SetClipboardData (CF_DIB, NULL);
                  has_set_dib = TRUE;
                  break;
@@ -1132,10 +1177,11 @@ _gdk_win32_selection_convert_to_dib (HGLOBAL  hdata,
       ptr = GlobalLock (hdata);
       memmove (ptr, ptr + sizeof (BITMAPFILEHEADER), size);
       GlobalUnlock (hdata);
-      if (!(hdatanew = GlobalReAlloc (hdata, size, 0))) {
-       WIN32_API_FAILED ("GlobalReAlloc");
-       GlobalFree (hdata); /* the old hdata is not freed if error */
-      }
+      if (!(hdatanew = GlobalReAlloc (hdata, size, 0)))
+       {
+         WIN32_API_FAILED ("GlobalReAlloc");
+         GlobalFree (hdata); /* the old hdata is not freed if error */
+       }
       return hdatanew;
     }